package com.yx.learn.domain;

import static javax.persistence.GenerationType.IDENTITY;



import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "tuser", catalog = "yx_01")
public class User implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private Position position;
	private Department department;
	private String employNo;
	private String employName;
	private String password;
	private String sex;
	private Date birthday;
	private String telephone;
	private String email;
	private String address;
	private String photoUrl;
	private Date createTime;
	private Set<UserAuthority> userauthorities = new HashSet<UserAuthority>(0);
	private Set<Usergroup> usergroups = new HashSet<Usergroup>(0);
	private Set<Userrole> userroles = new HashSet<Userrole>(0);

	// Constructors

	/** default constructor */
	public User() {
	}

	/** minimal constructor */
	public User(Position position, Department department, String employNo,
			String employName, String password, String sex, Date birthday,
			Date createTime) {
		this.position = position;
		this.department = department;
		this.employNo = employNo;
		this.employName = employName;
		this.password = password;
		this.sex = sex;
		this.birthday = birthday;
		this.createTime = createTime;
	}

	/** full constructor */
	public User(Position position, Department department, String employNo,
			String employName, String password, String sex, Date birthday,
			String telephone, String email, String address, String photoUrl,
			Date createTime, Set<UserAuthority> userauthorities,
			Set<Usergroup> usergroups, Set<Userrole> userroles) {
		this.position = position;
		this.department = department;
		this.employNo = employNo;
		this.employName = employName;
		this.password = password;
		this.sex = sex;
		this.birthday = birthday;
		this.telephone = telephone;
		this.email = email;
		this.address = address;
		this.photoUrl = photoUrl;
		this.createTime = createTime;
		this.userauthorities = userauthorities;
		this.usergroups = usergroups;
		this.userroles = userroles;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	//@ManyToOne(fetch = FetchType.LAZY)@JoinColumn(name="did",referencedColumnName="did")
	@ManyToOne(targetEntity=Position.class)
	@JoinColumn(name = "positionID", nullable = false,referencedColumnName="id")
	public Position getPosition() {
		return this.position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}

	//@ManyToOne(fetch = FetchType.LAZY)
	@ManyToOne(targetEntity=Department.class)
	@JoinColumn(name = "departmentID", nullable = false,referencedColumnName="id")
	public Department getDepartment() {
		return this.department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@Column(name = "employNo", nullable = false, length = 20)
	public String getEmployNo() {
		return this.employNo;
	}

	public void setEmployNo(String employNo) {
		this.employNo = employNo;
	}

	@Column(name = "employName", nullable = false, length = 64)
	public String getEmployName() {
		return this.employName;
	}

	public void setEmployName(String employName) {
		this.employName = employName;
	}

	@Column(name = "password", nullable = false, length = 20)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "sex", nullable = false, length = 2)
	public String getSex() {
		return this.sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "birthday", nullable = false, length = 0)
	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "telephone", length = 20)
	public String getTelephone() {
		return this.telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Column(name = "email", length = 64)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "address", length = 200)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "photoUrl", length = 500)
	public String getPhotoUrl() {
		return this.photoUrl;
	}

	public void setPhotoUrl(String photoUrl) {
		this.photoUrl = photoUrl;
	}

	@Column(name = "createTime", nullable = false, length = 0)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public Set<UserAuthority> getUserauthorities() {
		return this.userauthorities;
	}

	public void setUserauthorities(Set<UserAuthority> userauthorities) {
		this.userauthorities = userauthorities;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public Set<Usergroup> getUsergroups() {
		return this.usergroups;
	}

	public void setUsergroups(Set<Usergroup> usergroups) {
		this.usergroups = usergroups;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public Set<Userrole> getUserroles() {
		return this.userroles;
	}

	public void setUserroles(Set<Userrole> userroles) {
		this.userroles = userroles;
	}

}